package com.cman777.springc.mybatis.config;

import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;

import java.util.Properties;

/**
 * @author chenzhicong
 * @time 2020/10/26 18:05
 */

public class ConfigListener4RunSprboot implements ApplicationListener<ApplicationPreparedEvent> {
    @Override
    public void onApplicationEvent(ApplicationPreparedEvent event) {
        ConfigurableEnvironment env = event.getApplicationContext().getEnvironment();
        MutablePropertySources m = env.getPropertySources();
        Properties p = new Properties();
        //默认枚举typeHandler
        p.put("mybatis-plus.configuration.default-enum-type-handler","com.cman777.springc.mybatis.typehandler.EntityEnumIFaceHandler");
        //修改不忽视null值
        p.put("mybatis-plus.global-config.db-config.update-strategy", "NOT_NULL");
        //逻辑删除字段
        p.put("mybatis-plus.global-config.db-config.logic_delete_field", "state");
        //逻辑删除值
        p.put("mybatis-plus.global-config.db-config.logic_delete_value", "'10X'");
        //逻辑未删除值
        p.put("mybatis-plus.global-config.db-config.logic_not_delete_value", "'10A'");
        m.addFirst(new PropertiesPropertySource("mybatisPlusConfig",p));
    }


}
